<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class yingpin_model extends model
{
    private $host = 'http://47.104.30.217:8080/lanlingwang/php/interface';
//    private $host = 'http://192.168.12.137:8080/lanling/php/interface';

    /*
     * 1、获取用户详细信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getUser($uid){
        $data = array();
        $data['userId'] = $uid;

        $url = $this->host . '/user/userInfo';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        $res = $res['data']['appUser'];
        //修改数据字段结构
        $user = array();
        $user['user_id'] = $res['userId'];
        $user['username'] = $res['username'];
        $user['mobile'] = $res['mobile'];
        $user['password'] = $res['password'];
        $user['password_pay'] = $res['passwordPay'];
        $user['birthday'] = $res['birthday'];
        $user['age'] = $res['age'];
        $user['idcard'] = $res['idcard'];
        $user['realname'] = $res['realname'];
        $user['sex'] = $res['sex'];
        $user['sex_value'] = $res['sexValue'];
        $user['schooling_length'] = $res['schoolingLength'];
        $user['current_residence'] = $res['currentResidence'];
        $user['expected_working_city'] = $res['expectedWorkingCity'];
        $user['user_avatar'] = $res['userAvatar'];
        $user['signday'] = $res['signday'];
        $user['create_time'] = $res['createTime'];
        $user['update_time'] = $res['updateTime'];
        $user['signdays'] = $res['signdays'];
        $user['work_status'] = $res['workStatus'];
        $user['status'] = $res['status'];
        $user['status_value'] = $res['statusValue'];
        $user['deal_reason'] = $res['dealReason'];
        $user['deal_time'] = $res['dealTime'];
        return $user;
    }
    /*
     * 2、获取所有企业的信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getCompany(){
        $url = $this->host . '/ent/entList';

        $res = $this->postXmlCurl(null,$url,60);

        $res = json_decode($res,true);
        //return $res['data']['entList'];
        $companys = array();
        foreach($res['data']['entList'] as $k=>$v){
            $companys[$k]['enterprise_name'] = $v['enterpriseName'];
            $companys[$k]['enterprise_id'] = $v['enterpriseId'];
            $companys[$k]['company_name'] = $v['enterpriseName'];
            $companys[$k]['id'] = $v['enterpriseId'];
        }

        return $companys;

    }
    /*
     * 3、获取单条企业的信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getCompanyOnce($enterprise_id){
        $data = array();
        $data['enterpriseId'] = $enterprise_id;

        $url = $this->host . '/ent/entInfo';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        //return $res['data']['entInfo'];
        $company = array();
        $company['enterprise_name'] = $res['data']['entInfo']['enterpriseName'];
        $company['enterprise_id'] = $res['data']['entInfo']['enterpriseId'];
        $company['enterprise_logo'] = $res['data']['entInfo']['enterpriseLogo'];
        $company['economic_type'] = $res['data']['entInfo']['economicType'];
        $company['enterprise_facade'] =$res['data']['entInfo']['enterpriseFacade'];

        $company['enterprise_name'] =$res['data']['entInfo']['enterpriseName'];
        $company['enterprise_label'] =$res['data']['entInfo']['enterpriseLabel'];
        $company['employee_number_value'] =$res['data']['entInfo']['employeeNumberValue'];
        $company['introduction'] = $res['data']['entInfo']['introduction'];
        $company['enterprise_abbreviation'] = $res['data']['entInfo']['enterpriseAbbreviation'];
        return $company;
    }
    /*
     * 4、获取单条经纪人的信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getBusinessOnce($user_id){
        $data = array();
        $data['userId'] = $user_id;

        $url = $this->host . '/agent/findUserAgent';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
//        return $res['data']['agentBusiness'];
        $agent = array();
        $agent['agent_id'] = $res['data']['agentBusiness']['agentId'];
        return $agent;
    }
    /*
     * 5、修改agent_business表数据
     * usr:jdq
     * time:2019/4/15
     */
    public function editBusinessOnce($data = array()){


        $url = $this->host . '/agent/updateUserAgent';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 6、用户入职修改app_recommend表
     * usr:jdq
     * time:2019/4/15
     */
    public function editRecommendOnce($data = array()){
        $url = $this->host . '/reco/updateRecommend';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 7、查询app_recommend，获取用户是否是被推荐用户
     * usr:jdq
     * time:2019/4/15
     */
    public function getRecommendOnce($is_recommended_mobile){
        $data = array();
        $data['isRecommendedMobile'] = $is_recommended_mobile;

        $url = $this->host . '/reco/findRecommendByMobile';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['appRecommend'];
    }
    /*
     * 8、新增app_activity活动表数据
     * usr:jdq
     * time:2019/4/15
     */
    public function addActivityOnce($data = array()){
        $url = $this->host . '/act/saveActivity';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 9、查询agent与sys_user表，获取职位报名列表的用户相关信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getUserRealname($agent_id){
        $data = array();
        $data['id'] = $agent_id;

        $url = $this->host . '/agent/findAgentName';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data'];
    }
    /*
     * 10、查询enterprise_oss表，获取企业图片地址
     * usr:jdq
     * time:2019/4/15
     */
    public function getCompanyImage($company_id){
        $data = array();
        $data['enterpriseId'] = $company_id;

        $url = $this->host . '/ent/entOssList';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['entOssList'];
    }
    /*
     * 11、新增app_message_log表数据，插入投递记录
     * usr:jdq
     * time:2019/4/15
     */
    public function addMessageLog($data = array()){
        $url = $this->host . '/mes/saveAppMessageLog';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 12、修改签到天数
     * usr:jdq
     * time:2019/4/15
     */
    public function editUserSigndays($data = array()){
        $url = $this->host . '/user/updateUserSignDay';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 13、sys_user获取经纪人单条信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getSysUserOnce($data = array()){
        $url = $this->host . '/sys/findSysUser';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);

        return $res['data']['sysUser'];
    }
    /*
     * 14、查询agent表，获取经纪人相关信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getAgentOnce($userInfo_id){
        $data = array();
        $data['userInfoId'] = $userInfo_id;

        $url = $this->host . '/agent/findAgentInfoByUserId';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
//        return $res['data']['agent'];
        $agent = array();
        $agent = $res['data']['agent'];
        $agent['user_avatar'] = $res['data']['agent']['userAvatar'];
        return $agent;
    }
    /*
     * 15、查询agent_business，查询经纪人相关数据
     * usr:jdq
     * time:2019/4/15
     */
    public function getBusinessAll($agent_id){
        $data = array();
        $data['agentId'] = $agent_id;

        $url = $this->host . '/agent/findUserAgentInfoByAgentId';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['agentBusinessList'];
    }
    /*
     * 16、查询agent_business数量
     * usr:jdq
     * time:2019/4/15
     */
    public function getBusinessNum($data){
        $url = $this->host . '/agent/findAgentBusinessCount';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);

        return $res['data']['agentBusinessCount'];
    }
    /*
     * 17、查询agent_message，查询经纪人变更记录
     * usr:jdq
     * time:2019/4/15
     * todo 有点问题，胖子在忙第二天
     */
    public function getMessageAll($data = array()){

        $url = $this->host . '/agent/agentMessageList';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['agentMessageList'];
    }

    /*
     * 18、查询agent_track追踪记录
     * usr:jdq
     * time:2019/4/15
     */
    public function getTrackAll($data = array()){
        $url = $this->host . '/agent/agentTrackList';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['agentTrackList'];
    }
    /*
     * 19、新增agent_track追踪记录
     * usr:jdq
     * time:2019/4/15
     */
    public function addTrackOnce($data = array()){
        $url = $this->host . '/agent/saveAgentTrack';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);

        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 20、查询commission表，查询经纪人佣金
     * usr:jdq
     * time:2019/4/15
     */
    public function getCommissionOnce($data = array()){
        $url = $this->host . '/comm/commissionInfo';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['commission'];
    }
    /*
     * 21、查询commission表，查询经纪人佣金
     * usr:jdq
     * time:2019/4/15
     */
    public function getCommissionAll($data = array()){
        $url = $this->host . '/comm/commissionList';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['commissionList'][0];
    }
    /*
     * 22、修改agent_message表单条信息
     * usr:jdq
     * time:2019/4/15
     */
    public function editMessage($data = array()){
        $url = $this->host . '/agent/updateAgentMessage';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);

        if($res['code'] == 0){
            $res = true;
        }else{
            $res = false;
        }
        return $res;
    }
    /*
     * 23、查询agent_message表单条信息
     * usr:jdq
     * time:2019/4/15
     */
    public function getMessageOnce($id){
        $data = array();
        $data['id'] = $id;
        $url = $this->host . '/agent/agentMessageInfo';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['agentMessage'];
    }
    /*
     * 24、agent_business a LEFT JOIN app_user
     * usr:jdq
     * time:2019/4/15
     */
    public function getBusinessUserAll($data = array()){
        $url = $this->host . '/agent/findAgentBusinessList';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['agentBusinessList'];
    }
    /*
     * 25、agent_business a LEFT JOIN app_user
     * usr:jdq
     * time:2019/4/15
     */
    public function getBusinessUserOnce($data = array()){
        $url = $this->host . '/agent/findAgentBusinessInfo';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
//        return $res['data']['agentBusiness'];
        $business = array();
        $business['agent_id'] = $res['data']['agentBusiness']['agentId'];
        $business['user_id'] = $res['data']['agentBusiness']['userId'];
        $business['username'] = $res['data']['agentBusiness']['username'];
        $business['mobile'] = $res['data']['agentBusiness']['mobile'];
        $business['realname'] = $res['data']['agentBusiness']['realname'];
        $business['work_status'] = $res['data']['agentBusiness']['workStatus'];
        $business['user_avatar'] = $res['data']['agentBusiness']['userAvatar'];
        $business['create_time'] = $res['data']['agentBusiness']['createTime'];
        $business['handle_state'] = $res['data']['agentBusiness']['handleState'];
        $business['handle_time'] = $res['data']['agentBusiness']['handleTime'];
        $business['contact'] = $res['data']['agentBusiness']['contact'];
        $business['source'] = $res['data']['agentBusiness']['source'];
        return $business;

    }
    /*
     * 26、agent_business a LEFT JOIN app_user
     * usr:jdq
     * time:2019/4/15
     */
    public function getBusinessUserPage($data = array()){
        $url = $this->host . '/agent/findAgentBusinessByPage';

        $res = $this->postXmlCurl($data,$url,60);

        $res = json_decode($res,true);
        return $res['data']['agentBusinessList'];
    }






    //访问公共类方法
    private function postXmlCurl($xml, $url, $second = 30)
    {
        $ch = curl_init();
        //设置超时
        curl_setopt($ch, CURLOPT_TIMEOUT, $second);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //严格校验
        //设置header
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //post提交方式
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);


        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
        curl_setopt($ch, CURLOPT_TIMEOUT, 40);
        set_time_limit(0);
        //运行curl
        $data = curl_exec($ch);
        //返回结果
        if ($data) {
            curl_close($ch);
            return $data;
        } else {
            $error = curl_errno($ch);
            curl_close($ch);
            throw new BadRequestException('curl出错', $error);
        }
    }


}
?>